import { _HttpClient } from '@delon/theme';
import { QueryOptions } from 'src/app/project/model/common/query-options';
import { StudentCourseDTO } from 'src/app/project/model/icm/icm-student-academic/student-course/student-course.dto';
import { ApiPagedData } from 'src/app/project/model/common/api-paged-data';
import { Observable } from 'rxjs';
import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root',
})
export class StudentCourseService {
  private static URL = '/api/icm-student-course';

  constructor(private http: _HttpClient) {}

  /**
   * 分页查询学生选课信息
   * @param option 分页参数
   * @param studentId 所属学生id
   * @param courseName 课程名称
   * @param teacherName 授课老师
   * @param year 所属年度
   * @param termType 所属学期
   * @param studyStatus 修读状态
   */
  findOnePage(
    option: QueryOptions,
    studentId?: string,
    courseName?: string,
    teacherName?: string,
    year?: string,
    termType?: string,
    studyStatus?: string,
  ): Observable<ApiPagedData<StudentCourseDTO>> {
    const params = {};
    Object.assign(
      params,
      option,
      studentId ? { studentId } : {},
      courseName ? { courseName } : {},
      teacherName ? { teacherName } : {},
      year ? { year } : {},
      termType ? { termType } : {},
      studyStatus ? { studyStatus } : {},
    );
    return this.http.get<ApiPagedData<StudentCourseDTO>>(StudentCourseService.URL, params);
  }

  /**
   * 添加学生选课
   * @param studentCourseDTO 学生选课信息
   */
  create(studentCourseDTO: StudentCourseDTO): Observable<StudentCourseDTO> {
    return this.http.post<StudentCourseDTO>(StudentCourseService.URL, studentCourseDTO);
  }

  /**
   * 根据id查找学生选课
   * @param id 学生选课id
   */
  findById(id: string): Observable<StudentCourseDTO> {
    return this.http.get<StudentCourseDTO>(`${StudentCourseService.URL}/${id}`);
  }

  /**
   * 修改更新学生选课信息
   * @param id 学生选课id
   * @param studentCourseDTO 学生选课信息
   */
  complete(id: string, studentCourseDTO: StudentCourseDTO): Observable<StudentCourseDTO> {
    return this.http.put<StudentCourseDTO>(`${StudentCourseService.URL}/${id}`, studentCourseDTO);
  }

  /**
   * 根据id删除学生选课
   * @param id 学生选课id
   */
  delete(id: string): Observable<boolean> {
    return this.http.delete<boolean>(`${StudentCourseService.URL}/${id}`);
  }
}
